using ProxyServer.Quartz.Jobs;
using Quartz;

namespace ProxyServer.Quartz;

public static class QuartzHelpers
{
    public static async Task StartCheckSerivceCertificateOnce(
        IScheduler scheduler,
        Guid serviceId,
        CancellationToken cancellationToken)
    {
        var jobkey = CheckServiceCertificateJob.BuildServiceJobKey(serviceId);

        var trigger = TriggerBuilder.Create()
            .WithIdentity("common")
            .ForJob(jobkey)
            .WithSimpleSchedule(opt =>
            {
                opt.RepeatForever();
                opt.WithInterval(TimeSpan.FromSeconds(10));
            })
            .UsingJobData(new JobDataMap
            {
                [CheckServiceCertificateJob.ReCreateOrder] = false
            })
            .Build();

        await scheduler.ScheduleJob(trigger, cancellationToken);
    }
}